package com.ruyuan.engine.datagen;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class RuleDataGen {
    static Connection conn;
    static PreparedStatement preparedStatement;
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://hadoop5:3306/RY_RULE_RISK?useUnicode=true&characterEncoding=utf8", "root", "hadoop");
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws Exception {
        generatorRule();
    }
    //生成规则数据
    public static void generatorRule() throws Exception {
        String ruleJson = FileUtils.readFileToString(new File("flink_engine_module/rules/rule1.json"), "utf-8");
        String ruleDrl = FileUtils.readFileToString(new File("flink_engine_module/rules/rule1.drl"), "utf-8");
        preparedStatement = conn.prepareStatement("insert into rule_bz (rule_id,rule_name,rule_conditions,rule_drl,create_time,modify_time,operator_id,is_active) values (?,?,?,?,?,?,?,?)");
        preparedStatement.setInt(1,1);
        preparedStatement.setString(2,"pay_count");
        preparedStatement.setString(3,ruleJson);
        preparedStatement.setString(4,ruleDrl);
        preparedStatement.setLong(5,System.currentTimeMillis());
        preparedStatement.setString(6,"2022-05-01 13:11:11");
        preparedStatement.setInt(7,842682542);
        preparedStatement.setInt(8,1);
        preparedStatement.execute();
        preparedStatement.close();
        conn.close();
    }
}
